package com.gtq.uhome.controller;

import com.gtq.uhome.result.Result;
import com.gtq.uhome.service.LogisticsService;
import com.gtq.uhome.vo.LogisticsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 站点后台，派送列表
 */
@CrossOrigin
@Controller
@RequestMapping("/logistics")
@ResponseBody
@Api(tags = "站点后台，新建物流单接口说明文档，田小凡")
public class LogisticsController {

    @Resource
    LogisticsService logisticsService = null;

    /**
     * 新建物流单
     * @param logisticsVo
     * @return
     */
    @PostMapping
    @ApiOperation(value = "配送列表，新建物流单",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supId",value = "选择消耗物料的id",required = true),
            @ApiImplicitParam(name = "supCount",value = "物料消耗数量",required = true),
            @ApiImplicitParam(name = "orderId",value = "订单id，前台传入",required = true),
            @ApiImplicitParam(name = "categoryOne",value = "商品一级分类",required = true),
            @ApiImplicitParam(name = "categoryTwo",value = "商品二级分类",required = true),
            @ApiImplicitParam(name = "categoryThree",value = "商品三级分类",required = true),
            @ApiImplicitParam(name = "count",value = "数量",required = true),
            @ApiImplicitParam(name = "heavy",value = "重量",required = true),
            @ApiImplicitParam(name = "price",value = "金额",required = true),
            @ApiImplicitParam(name = "agingCode",value = "时效产品状态，生鲜/常温",required = true),
            @ApiImplicitParam(name = "consigneePhoneNumber",value = "收货人电话",required = true),
            @ApiImplicitParam(name = "consigneeName",value = "收货人姓名",required = true),
            @ApiImplicitParam(name = "street",value = "地址",required = true),
            @ApiImplicitParam(name = "consigneeAddress",value = "详细地址",required = true),
            @ApiImplicitParam(name = "standbyPhoneNumber",value = "收货人备用电话",required = true),
            @ApiImplicitParam(name = "userName",value = "发货人姓名",required = true),
            @ApiImplicitParam(name = "userPhoneNumber",value = "发货人电话",required = true),
    })
    public Result insertLogistics(@RequestBody LogisticsVo logisticsVo){
        Boolean isInsert = logisticsService.insertLogistics(logisticsVo);
        if(isInsert){
            return Result.ok("添加成功！");
        }else {
            return Result.failed("添加失败！");
        }

    }

    /**
     * 查询物料名称与商品列表
     * @return
     */
    @GetMapping
    @ApiOperation(value = "查询物料名称与商品列表",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "aName",value = "一级分类名称"),
            @ApiImplicitParam(name = "bName",value = "二级分类名称"),
            @ApiImplicitParam(name = "cName",value = "三级分类名称"),
            @ApiImplicitParam(name = "categoryOne",value = "一级分类id"),
            @ApiImplicitParam(name = "categoryTwo",value = "二级分类id"),
            @ApiImplicitParam(name = "categoryThree",value = "三级分类id"),
            @ApiImplicitParam(name = "bParentId",value = "二级分类父id"),
            @ApiImplicitParam(name = "cParentId",value = "三级分类父id"),
    })
    public Result findSupName(){
        List<LogisticsVo> supName = logisticsService.findSupName();
        List<LogisticsVo> categoryName = logisticsService.findCategoryName();
        Map<String,Object> map = new HashMap<>();
        map.put("supName",supName);
        map.put("categoryName",categoryName);
        return Result.ok(map);
    }
}
